package com.yunhe.authority.domain.authority;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.neo4j.ogm.annotation.Property;
import org.springframework.data.neo4j.annotation.QueryResult;

import java.io.Serializable;

/**
 * 资源树对象
 * @author liuronglei
 */
@ApiModel(value = "ResourceTree", description = "资源树")
@QueryResult
public class ResourceTree implements Serializable, Comparable<ResourceTree> {
    @ApiModelProperty(value = "资源ID")
    @Property(name = "id")
    private Long id;
    @ApiModelProperty(value = "资源类型")
    @Property(name = "type")
    private String type;
    @ApiModelProperty(value = "资源代码")
    @Property(name = "code")
    private Long code;
    @ApiModelProperty(value = "资源对象")
    @Property(name = "object")
    private Object object;
    @ApiModelProperty(value = "是否叶子节点")
    @Property(name = "leaf")
    private Boolean leaf;

    @Override
    public int compareTo(ResourceTree o) {
        if (this.type == null || o.getType() == null) {
            return 0;
        }
        if (this.type.compareTo(o.getType()) > 0) {
            return 1;
        }
        if (this.type.compareTo(o.getType()) == 0) {
            if (this.getCode().compareTo(o.getCode()) > 0) {
                return 1;
            }
            if (this.getCode().compareTo(o.getCode()) == 0) {
                return 0;
            }
            if (this.getCode().compareTo(o.getCode()) < 0) {
                return -1;
            }
        }
        if (this.type.compareTo(o.getType()) < 0) {
            return -1;
        }
        return 0;
    }

    public Object getObject() {
        return object;
    }

    public void setObject(Object object) {
        this.object = object;
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public Boolean getLeaf() {
        return leaf;
    }

    public void setLeaf(Boolean leaf) {
        this.leaf = leaf;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}
